<script type="text/javascript">
    $(document).ready(function(){
        $('#form-register input').live('change',function(){
            var input=$('#'+$(this).attr('id'));

            input.removeClass("error-input");
            $("#"+input.attr("id")+'_em_').html('');
        });
    });
</script>
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'form-register',
    'action'=>Yii::app()->createUrl('user/register/register'),
    'method'=>'post',
    'enableAjaxValidation'=>true,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
        'validateOnChange'=>true,
        'afterValidate'=>'js:function(form, data, hasError){
            if(hasError){
                $(".form-error",form).each(function(){
                    var error=$(this);
                    if(error.html()){
                        var input=$("#"+error.attr("id").replace("_em_",""));
                        if(!input.value) error.html("");
                        input.addClass("error-input");
                    }
                });
            }
            return !hasError;
        }',
    ),
)); ?>

    <?php echo CHtml::errorSummary(array($user, $profile)); ?>

    <?php echo $form->textField($user,'userName',array(
        'placeholder'=>$user->getAttributeLabel('userName').' *',
        'class'=>'form-input',
    )) ?>
    <?php echo $form->error($user,'userName',array(
        'class'=>'form-error',
    )); ?>

    <?php echo $form->textField($user,'email',array(
        'placeholder'=>$user->getAttributeLabel('email').' *',
        'class'=>'form-input',
    )) ?>
    <?php echo $form->error($user,'email',array(
        'class'=>'form-error',
    )); ?>

    <?php echo $form->textField($profile,'firstName',array(
        'class'=>'form-input',
        'placeholder'=>$profile->getAttributeLabel('firstName').' *',
    )); ?>
    <?php echo $form->error($profile,'firstName',array(
        'class'=>'form-error',
    )); ?>

    <?php echo $form->textField($profile,'lastName',array(
        'class'=>'form-input',
        'placeholder'=>$profile->getAttributeLabel('lastName').' *',
    )) ?>
    <?php echo $form->error($profile,'lastName',array(
        'class'=>'form-error',
    )); ?>

    <?php echo $form->dropDownList($profile,'sex',array(0=>'Мальчик',1=>'Девочка'),array(
        'class'=>'form-input',
    )); ?>
    <?php echo $form->error($profile,'sex',array(
        'class'=>'form-error',
    )); ?>

    <?php echo $form->passwordField($user,'password',array(
        'class'=>'form-input',
        'placeholder'=>$user->getAttributeLabel('password').' *',
    )) ?>
    <?php echo $form->error($user,'password',array(
        'class'=>'form-error',
    )); ?>

    <?php echo $form->passwordField($user,'retypePassword',array(
        'class'=>'form-input',
        'placeholder'=>$user->getAttributeLabel('retypePassword').' *',
    )) ?>
    <?php echo $form->error($user,'retypePassword',array(
        'class'=>'form-error',
    )); ?>

    <?php if(CCaptcha::checkRequirements()): ?>
        <?php $this->widget('CCaptcha',array(
            'captchaAction'=>'/user/register/captcha',
            'clickableImage'=>true,
            'showRefreshButton'=>false,
            'imageOptions'=>array(
                'style'=>'cursor:pointer;',
                'alt'=>'Проверочный код',
                'title'=>'Чтобы обновить картинку с проверочным кодом, нажмите на неё',
            ),
        )); ?>
        <?php echo $form->textField($user,'verifyCode',array(
            'class'=>'form-input',
            'placeholder'=>$user->getAttributeLabel('verifyCode').' *',
        )) ?>
        <?php echo $form->error($user,'verifyCode',array(
            'class'=>'form-error',
        )); ?>
    <?php endif; ?>

    <?php echo CHtml::submitButton('Регистрация'); ?>

<?php $this->endWidget(); ?>